package com.ndp.fb.scheduler.job.accountresource;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ndp.fb.constant.ConfigConst;
import com.ndp.fb.mq.api.service.schedulerservice.business.syncbusiness.SyncAccountResourceService;
import com.ndp.fb.rdb.api.EntrustAccountRdbService;
import com.ndp.fb.rdb.model.EntrustAccount;
import com.ndp.fb.scheduler.annotation.CronScheduled;
import com.ndp.fb.util.ListUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Elvis.Xiong on 2015/4/9 17:04.
 * Email elvis.xiong@ndpmedia.com
 * 帐号图片视频同步
 */
@Component
public class SyncAccountResourceJob {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Reference
    SyncAccountResourceService syncAccountResourceService;
    @Reference
    EntrustAccountRdbService entrustAccountRdbService;


    @CronScheduled(cronkey = ConfigConst.SCHEDULE_SYNC_ACCOUNT_INS_CRON, enablekey = ConfigConst.SCHEDULE_SYNC_ACCOUNT_INS_ENABLE)
    public void syncAccountIns() {
        logger.info("拉取ins账号开始");
        List<EntrustAccount> entrustAccounts = entrustAccountRdbService.findAllAdAccount();
        if (ListUtil.isEmpty(entrustAccounts))
            return;
        try {
            for (EntrustAccount entrustAccount : entrustAccounts) {
                logger.info("ins账号{}开始拉取fb了", entrustAccount.getFbAccountId());
                syncAccountResourceService.syncAccountIns(entrustAccount.getFbAccountId());
            }
        } catch (Exception e) {
            logger.error("拉取ins账号出错", e);
        }

    }
}
